<?php

namespace app\modules\controllers;

use app\modules\models\Admin;
use Yii;
use yii\web\Controller;

class PublicController extends Controller
{
    public function actionLogin()
    {
        $this->layout = false;
        $model        = new Admin();

        if (Yii::$app->request->isPost) {
            if ($model->login(Yii::$app->request->post())) {
                return $this->redirect(['default/index']);
            }
        }

        return $this->render('login', [
            'model' => $model,
        ]);
    }

    public function actionLogout()
    {
        Yii::$app->session->remove('admin');
        if (!isset(Yii::$app->session['admin']['isLogin'])) {
            return $this->redirect(['public/login']);
        }
        $this->goBack();
    }

    public function actionSeekpassword()
    {
        $this->layout = false;
        $model        = new Admin();

        if (Yii::$app->request->isPost) {
            if ($model->seekPassword(Yii::$app->request->post())) {
                Yii::$app->session->setFlash('info','邮件发送成功,请查收');
            }
        }

        return $this->render('seek', [
            'model' => $model,
        ]);
    }
}